package org.restoran.service;

import org.restoran.model.Order;

/**
 * @author Snisar Bogdan.
 */
public interface OrderService extends CrudService<Order, Integer>, BeanParserService<Order> {

    /**
     * Save as creating new Order if it is new instance {@link org.restoran.model.Order#isNew()},
     * and update in other case.
     *
     * @param entity entity
     * @return entity after persist
     * @throws ServiceException if trying create entity without no related
     * {@link org.restoran.model.Table} id.
     */
    public Order save(Order entity);

    /**
     * Update existed order.
     *
     * @param forUpdate value for update
     * @return updated Order
     * @throws ServiceException is this is order with {@link org.restoran.model.Order#isNew()} true
     * @throws NullPointerException if {@code forUpdate} is null
     */
    public Order updateExisted(Order forUpdate);

    /**
     * Close Order and set related {@link org.restoran.model.Table} Table status
     * to FREE {@link org.restoran.model.TableStatus#FREE}.
     *
     * @param order order ro close
     * @return closed order
     * @throws ServiceException if it is {@link org.restoran.model.Order#isNew()} isNew = true,
     *  or status not equals to {@link org.restoran.model.OrderStatus#CLOSED}
     */
    public Order closeOrder(Order order);

}
